/**
 * @author caochaoyu
 * @param{String}
 */
function star() {
    
    function random(min, max) {
        return Math.floor(Math.random() * (max - min + 1) + min)
    }
   
    var time1 = setInterval(function () {
    
        var imgObj = document.createElement('img')
    
        imgObj.src = './img/s66.png'
     
        var max = 200;
        var min = 120;
     
        imgObj.width = random(min, max)
        
        imgObj.style.position = 'absolute'
        var min = 0        

        var max = (window.innerWidth || document.documentElement.clientWidth) - imgObj.width

        imgObj.style.left = random(min, max) + 'px'
   
        var max = (window.innerHeight || document.documentElement.clientHeight) - imgObj.width
       
        imgObj.style.top = random(min, max) + 'px'
   
        document.body.appendChild(imgObj)
    }, 1000);


    document.querySelector('body').onclick = function (evt) {
   
        var e = evt || window.event
      
        var target = e.target || e.srcElement
       
        if (target.nodeName == 'IMG') {
            document.querySelector('body').removeChild(target)
           
            var num = parseInt(document.querySelector('.number').style.width)
            num++
            document.querySelector('.number').style.width = num + '%'
        }
    }


    var time2 = setInterval(function () {
        var num = parseInt(document.querySelector('.number').style.width)
        
        num -= 2
      
        if (num == 0) {
        
            clearTimeout(time2)
            clearTimeout(time1);
            document.querySelector('body').onclick = null
            alert('游戏结束')
        }
    }, 1000);
}
star();